<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>权证名称搜索列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="label">权证名称</div>
                <div class="field">
                    <input name="warrantName" ligerui="width:150" id="warrantName" type="text" class="ui-textbox" value="">
                </div>
            </div>

			<div class="fieldBox">
				<div class="label">权证类别</div>
				<div class="field">
					<select id="warrantType"  name="warrantType"  ligerui="width: 160">
						<option value="">请选择</option>
						<c:forEach items="${warrantTypeList}" var="item">
							<option value="${item.key}">${item.value}</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="fieldBox">
                <div class="label">状态</div>
                <div class="field">
                    <select name="isValid" id="isValid" ligerui="width:150">
                        <option value="" seleted>请选择</option>
                        <option value="1" seleted>启用</option>
                        <option value="0" seleted>废弃</option>
                    </select>
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-round">查询</span>
               <span id="clearBtn" onclick="clearBtnEvent();" class="sq-button sq-button-round">清空</span>
            </div>
            
            <!-- hide data -->
		    <div class="fieldBox col_100" style="display:none;">
		       <div class="field">
		          <input name="multiRowName" id="multiRowId" type="text" class="ui-textbox" value="${multiRow}">
		       </div>
		    </div>
        </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>
<script type="text/javascript">
	var grid = null;
	var cstRlFlag = '${cstRlFlag}';
	$(function () {
	    initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    searchBtnEvent();
	});
	
	
	//清空按钮事件
	function clearBtnEvent(){
		$('#searchBar :input[name]').each(
			function () {
				$(this).val('');
			}
		);
		$("#warrantType").val("");
		$("#isValid").val("");
	}
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		 $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
// 	         data["crtTm"] = $("#crtTm").val();
// 	         alert(JSON.stringify(data));
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
	}
	
	//定义选择行数据-存资料名称
	var warrantNames = new Array();
	//加载表单数据
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
<%-- 	    	url: '<%=path%>/warrant/warrantfilemanage/initListDownload.do', --%>
			url:'<%=path%>/archive/arcBscInfo/initList.do',
	    	method : 'get',
	    	parms:getSearchParams(),
	        columns: [
	             { display: '资料名称', name: 'warrantName', minWidth: 60, enabledSort:true },
	            { display: '权证类型', name: 'warrantTypeNm', minWidth: 60 , enabledSort:true}, 
	            { display: '状态', name: 'isValid', align:'center', enabledSort:true,
					render:function (rowdata, rowindex, value){
							return (value == "1")?"启用":"废弃";
					}
				}
	        ],
	        pageSize:10,
	        pageSizeOptions: [10, 20, 40, 50, 100],
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        //选择行事件-zrc-20181226
            onSelectRow : function (rowdata, rowid, rowobj){
            	var warrantName = "'"+rowdata.warrantName+"'";
            	//重复不添加
            	if(warrantNames.join().indexOf(warrantName) == -1){
            		warrantNames[warrantNames.length] = warrantName;
            		//$.ligerDialog.alert("warrantNames.length=["+warrantNames.length+"];warrantNames=["+warrantNames.join()+"]");//注释测试弹框
            	}
            },
            //取消选择行事件-zrc-20181226
            onUnSelectRow : function (rowdata, rowid, rowobj){
				var warrantName = "'"+rowdata.warrantName+"'";
				//删除已存数据
    			for(var i=0;i<warrantNames.length;i++){
    				if(warrantNames[i] == warrantName){
    					warrantNames.splice(i, 1);
    				}
    			}
    			//$.ligerDialog.alert("warrantNames.length=["+warrantNames.length+"];warrantNames=["+warrantNames.join()+"]");//注释测试弹框
            },
            //显示完数据事件-zrc-20181226
            onAfterShowData: f_onAfterShowData,
	        rownumbers:true
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    
	    var multiRow = $("#multiRowId").val();
	    if(StringUtils.isEmpty(multiRow)){
	    	 grid.options.isSingleCheck=false;
	    }else if(multiRow == "false"){
	    	grid.options.isSingleCheck=true;
	    }else if(multiRow == "true"){
	    	grid.options.isSingleCheck=false;
	    }
	}
	//加载默认选中行-张荣聪-20181226
    function f_onAfterShowData(currentData){
    	if(currentData!=null){
	    	var arr = eval(currentData);
	        var rows = arr.rows;
            var manager = $("#ligergrid1").ligerGetGridManager();
	        for(var i=0;i<rows.length;i++){
	        	var warrantName = "'"+rows[i].warrantName+"'";
	        	for(var j=0;j<warrantNames.length;j++){
	        		//对比权证名称
	        		if(warrantNames[j] == warrantName){
	            		manager.select(i);//此时会调用onSelectRow选中行事件
	            		break;//节省时间
		        	}
	        	}
	        }
    	}
    }
	
	
	//返回给调用窗口,返回结果为集合
	frameElement.dialog.onOk = function(){
// 		var selectedRows = grid.getSelectedRows();
// 		//判断多选还是单选
// 		var cstMap = new HashMap();
// 		if(grid.options.isSingleCheck == true){
// 			//单选
// 			if(selectedRows.length != 1){
// 				UIUtils.alertWarning(LogUtils.LOG_CMM_SELECT_ONLY_A_ROW);
// 				return;
// 			}
// 			var _id = selectedRows[0].id;
// 			var _cstNm = selectedRows[0].warrantName;
// 			cstMap.put(_id, _cstNm);
// 		}else{
// 			//多选
// 			if(selectedRows.length <=0){
// 				UIUtils.alertWarning(LogUtils.LOG_CMM_SELECT_MORE_ROW);
// 				return;
// 			}
// 			var i = 0;
// 			for (i = 0; i < selectedRows.length; i++) {
// 				var _id = selectedRows[i].id;
// 				var _cstNm = selectedRows[i].warrantName;
// 				cstMap.put(_id, _cstNm);
// 			}
// 		}
// 		return cstMap;
		return warrantNames;
	}
	
	frameElement.dialog.onCancel = function (){
		frameElement.dialog.close();
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
		
	
	function clearBtn(){
		var form = new liger.get("searchBar");
		form.clear();
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	
</script>
</body>
</html>